<form class="layui-form" action="">
  <script type="text/html" template lay-done="layui.data.done(d.params)">
    <div class="layui-form-item">
      <label class="layui-form-label">渠道名称</label>
      <div class="layui-input-inline">
        <input type="text" name="name" max-length="64" lay-verify="required" autocomplete="off" placeholder="渠道名称"
               value="{{d.params.name || ''}}" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">上级渠道</label>
      <div class="layui-input-inline">
        <input type="text" name="parent_code" max-length="64" autocomplete="off" placeholder="上级渠道编码"
               value="{{d.params.parent_code || ''}}" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">联系人</label>
      <div class="layui-input-inline">
        <input type="text" name="contact" lay-verify="required" autocomplete="off" class="layui-input"
               value="{{d.params.contact || '' }}">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">手机号</label>
      <div class="layui-input-inline">
        <input type="tel" name="mobile" lay-verify="required|mobile" autocomplete="off" class="layui-input"
               value="{{d.params.mobile || '' }}">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">每日最大注册人数</label>
      <div class="layui-input-inline">
        <input type="number" name="daily_register_limit" lay-verify="required" autocomplete="off" class="layui-input"
               value="{{d.params.daily_register_limit || 0 }}">
      </div>
      <div class="layui-inline layui-form-mid">
        为0时表示不限制
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-form-label">封面图片</div>
      <div class="layui-input-inline">
        <div id="cover_image"></div>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline">
        <input type="hidden" value="{{d.params.id  || ''}}" name="id"/>
        <button class="layui-btn" lay-submit="" lay-filter="submit_channel">提交</button>
      </div>
    </div>
  </script>
</form>

<script>
  layui.data.done = function (obj) {
    console.log(obj)
    layui.use(['fox_upload'], function () {
      var $ = layui.$
        , admin = layui.admin
        , form = layui.form
        , fox_upload = layui.fox_upload

      //设置当前页面的通用参数
      fox_upload.set({
        url: 'agent-admin/products/image'
        , headers: {
          Authorization: admin.getAccessToken('Bearer'),
        }
      })

      //上传控件初始化
      fox_upload.render({
        elem: '#cover_image'
        , name: 'cover_image_url'
        , text: '封面图片'
        , value: obj.cover_image_url
      })

      /* 自定义验证规则 */
      form.verify({
        name: function (value) {
          if (value.length < 1) {
            return '请输入渠道名称';
          }
          if (value.length > 64) {
            return '渠道名称过长';
          }
        },
        username: function (value) {
          if (value.length < 1) {
            return '请输入联系人名称';
          }
          if (value.length > 64) {
            return '联系人名称过长';
          }
        },
        mobile: function (value) {
          var res = /^[1][3,4,5,6.7,8,9][0-9]{9}$/;
          if (!res.test(value)) {
            return '手机号输入有误';
          }
        }
      });
    });
  }
</script>
